<?php
require_once('../phplib/include.inc.php');

class DoLogin{
	static function ParseRequest(){
		$ERRMSG = "";
		$pwd = $_POST['pwd'];
		$rem = $_POST['remember'];
		$uid = $_POST['uid'];
		if(strlen($pwd) == 0){
			$ERRMSG .= "请输入密码.<br />";
		}
		if(strlen($uid) == 0){
			$ERRMSG .= "请正确填写用户ID或用户名";
		}
		$rem = strtolower($rem) == "on" ? true : false;
		if($ERRMSG != ""){
			PageBase::Go('../home/error.php',$ERRMSG);
		}
		// The param is valid.
		if(intval($uid) == 0){
			$db = getDb();
			$db->connect();
			$uid = intval($db->fetchScalar("SELECT uid FROM user_t WHERE uname={0}",$uid));
		}
		$result = Auth::DoLogin($uid,$pwd,$rem);
		if($result !== true){
			PageBase::Go('../home/error.php',$result);
		}
		Util::AddLog("登录系统.");
		PageBase::Go('../home/index.php');
	}
}
DoLogin::ParseRequest();
?>